// src/store/index.js
import { configureStore, createSlice } from '@reduxjs/toolkit';
// 导入 posts 切片的 reducer
import postsReducer from './postsSlice';

// 计数器切片（之前的示例代码）
const counterSlice = createSlice({
  name: 'counter',
  initialState: { value: 0 },
  reducers: {
    increment: (state) => { state.value += 1; },
    decrement: (state) => { state.value -= 1; },
    incrementByAmount: (state, action) => { state.value += action.payload; }
  }
});

// 导出计数器相关的 action
export const { increment, decrement, incrementByAmount } = counterSlice.actions;

// 配置 store，合并所有切片的 reducer
export const store = configureStore({
  reducer: {
    counter: counterSlice.reducer,  // 计数器切片的 reducer
    posts: postsReducer             // 新增：posts 切片的 reducer
  }
});